﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class manage_my_newsForecast_edit : AdminpageBase
{
    protected string strtitle = ReadRequest.RequestString("title");
    protected string ctype = ReadRequest.RequestString("t");
    protected long type = ReadRequest.RequestLong("type");
    protected long id = ReadRequest.RequestLong("id");
    //protected Model.NewsSite model = new Model.NewsSite();
    Model.ForecastPost model = new Model.ForecastPost();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            inidata();
        }
    }
    private void inidata()
    {
        try
        {
            if (ctype != null && "edit".Equals(ctype))
            {
                model = BLL.ForecastPost.GetModel(id);
                if (model != null)
                {
                    texteid.Text = id.ToString();
                    txtTitle.Text = model.Title;
                    txtContent.Value = model.Content;
                    ////中奖说明
                    //if (type == 4)
                    //{
                    //    caipiaoType.SelectedValue = model.IsShow.ToString();
                    //}
                }
            }
            else
            {
                ctype = "ad";
            }
        }
        catch
        {
            ctype = "ad";
        }
    }

    //提交按钮事件
    protected void btn_submit_Click(object sender, EventArgs e)
    {
        save_Newscont();
    }
    private void save_Newscont()
    {
        //获取登录信息
        Model.Manageadmin loginUserInfo_cur = BLL.CMember.ManageadminLoginInfo();
        //没有登录
        if (loginUserInfo_cur == null)
        {
            alertmessageAndGoback("保存失败");
            return;
        }
        bool isadd = true;
        if (ctype != null && "ad".Equals(ctype.ToLower()))
        {
            isadd = true;
        }
        else
        {
            isadd = false;
        }
        if (isadd)
        {
            int LotteryType=1;
            if(type==8)
            {
                LotteryType = 1;
            }
            else if(type==9)
            {
                LotteryType = 2;
            }
            else if(type==10)
            {
                LotteryType = 5;
            }
            Model.ForecastPost forecastPost = new Model.ForecastPost();
            forecastPost.AddTime = DateTime.Now;
            forecastPost.Content = txtContent.Value;
            forecastPost.LotteryType = LotteryType;
            forecastPost.Title = txtTitle.Text;
            if(postType.SelectedIndex.ToString()=="0")
            {
                forecastPost.PostType = "预测推荐";
            }
            else if(postType.SelectedIndex.ToString()=="1")
            {
                forecastPost.PostType = "投注技巧";
            }
            else if(postType.SelectedIndex.ToString()=="2")
            {
                forecastPost.PostType = "中奖故事";
            }
           
            forecastPost.UserID = Convert.ToInt32(loginUserInfo.Id);
            if (BLL.ForecastPost.Add(forecastPost) > 0)
            {
                alertmessageAndGo("保存成功！", "/manage/my_newsForecast.aspx?type=" + type + "&title=" + strtitle);
                return;
            }
            else
            {
                alertmessageAndGoback("保存失败");
                return;
            }
        }
        else
        {
            Model.ForecastPost model = BLL.ForecastPost.GetModel(id);
            //Model.NewsSite model = BLL.NewsSite.GetModel(id);
            if (model != null)
            {
                model.Title = txtTitle.Text;
                model.Content = txtContent.Value;
                if ((new DateTime()).Equals(model.AddTime))
                {
                    model.AddTime = DateTime.Now;
                }

                if (BLL.ForecastPost.Update(model) > 0)
                {
                    alertmessageAndGo("保存成功！", "/manage/my_newsForecast.aspx?type=" +type + "&title=" + strtitle);
                    return;
                }
                else
                {
                    alertmessageAndGoback("保存失败");
                    return;
                }
            }
        }
    }
}